﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.Content;
using Android.OS;

namespace GBU.Services.Common
{
    public class CommonServiceConnection<T> : Java.Lang.Object, IServiceConnection
    {
        CommonServiceBinder<T> _binder;

        public CommonServiceBinder<T> Binder
        {
            get
            {
                return _binder;
            }
        }

        public CommonServiceConnection()
        {
        }

        public void OnServiceConnected(ComponentName name, IBinder service)
        {
            var binder = service as CommonServiceBinder<T>;

            if (binder != null)
            {
                // keep instance for preservation across configuration changes
                this._binder = binder;
            }
        }

        public void OnServiceDisconnected(ComponentName name)
        {
            _binder = null;
            //_activity.IsBound = false;
        }
    }
}
